package gamePlay;

import java.util.*;

/* 
 * The Computer Player class extends the Player class.
 * It overrides the submitGuess and placeBet methods.
 * 
 * submitGuess method: Jim Choinoski
 * placeBet method: Jim Jensen
 */

public class ComputerPlayer extends Player{
	
	private Random generator = new Random();
	
	public ComputerPlayer(String name){
		super(name);
	}
	
	//Jim Choinoski
	@Override
	public void submitGuess(int answer){
		
		Random intGenerator = new Random();
		Random boolGenerator = new Random();
		int number = 0;
		boolean bool = boolGenerator.nextBoolean();
		int deviation = 0;
		
		// assign the range of deviation based upon the size of the answer
		if (answer < 10){
			deviation = 5;
		}
		else if (answer < 100){
			deviation = 50;
		}
		else {
			deviation = 100;
			// deviation = answer / 2;
		}
		
		// if the random boolean is true, add a random number within the deviation
		// if the random boolean is false, subtract a random number within the deviation
		if (bool == true){
			number = answer + (intGenerator.nextInt(deviation) + 1);
		}
		else if (bool == false){
			number = answer - (intGenerator.nextInt(deviation) + 1);
			if (number < 0){
				number = -number;
			}
		}

		//System.out.println(number);
		Guess guess = new Guess(getPlayer_name(), number);
		getGame().receiveGuess(guess);
	}
	
	/**
	 * AI for the automated player to chose where to bet
	 */
	public void chooseBet() {
		int choice;
		int availPermaChips = getPermanent_chips();
		int availGameChips = getGame_chips();
		
		while(availPermaChips + availGameChips > 0) {
			choice = (int) (Math.random() * currentGame.getGuesses().size());
			int betGameChips = (int) (Math.random() * availGameChips);
			int betPermaChips = (int) (Math.random() * availPermaChips);
			
			placeBet(choice, betPermaChips, betGameChips);
			
			availPermaChips -= betPermaChips;
			availGameChips -= betGameChips;
			if(availGameChips <= 1 && availPermaChips <= 1){
				break;
			}
		}	
	}
}